package com.cy.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

/**
 * Description: 添加描述
 * date: 2021/3/19 0019 17:51
 *
 * @author Mr.xiaoshi
 * @since JDK 1.8
 */
@Component
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LocalTime now = LocalTime.now();  //获取当前时间
        int hour = now.getHour();   //获取小时
        if(hour<=6||hour>=22)
            throw new RuntimeException("请在 6~10 点进行访问");
        return true;
    }
}
